package com.platform.qujia.service.impl;


import com.platform.qujia.dao.PresentAmountRecordMapper;
import com.platform.qujia.pojo.PresentAmountRecord;
import com.platform.qujia.service.PresentAmountRecordService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * (PresentAmountRecord)表服务实现类
 *
 * @author makejava
 * @since 2023-10-26 16:01:32
 */
@Service("presentAmountRecordService")
public class PresentAmountRecordServiceImpl implements PresentAmountRecordService {
    @Resource
    private PresentAmountRecordMapper presentAmountRecordMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PresentAmountRecord queryById(Long id) {
        return this.presentAmountRecordMapper.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param presentAmountRecord 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<PresentAmountRecord> queryByPage(PresentAmountRecord presentAmountRecord, PageRequest pageRequest) {
        long total = this.presentAmountRecordMapper.count(presentAmountRecord);
        return new PageImpl<>(this.presentAmountRecordMapper.queryAllByLimit(presentAmountRecord, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param presentAmountRecord 实例对象
     * @return 实例对象
     */
    @Override
    public PresentAmountRecord insert(PresentAmountRecord presentAmountRecord) {
        this.presentAmountRecordMapper.insert(presentAmountRecord);
        return presentAmountRecord;
    }

    /**
     * 修改数据
     *
     * @param presentAmountRecord 实例对象
     * @return 实例对象
     */
    @Override
    public PresentAmountRecord update(PresentAmountRecord presentAmountRecord) {
        this.presentAmountRecordMapper.update(presentAmountRecord);
        return this.queryById(presentAmountRecord.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.presentAmountRecordMapper.deleteById(id) > 0;
    }


    @Override
    public PresentAmountRecord createRecord(BigDecimal presentAmt, String bussinessName, String mobilePhone, String orderNo, String purpose, Long cecId, Long ccsdId) {
        PresentAmountRecord presentAmountRecord=new PresentAmountRecord();
        presentAmountRecord.setPresentAmount(presentAmt);
        presentAmountRecord.setBusinessName(bussinessName);
        presentAmountRecord.setMobilePhone(mobilePhone);
        presentAmountRecord.setOrderNo(orderNo);
        presentAmountRecord.setPurpose(purpose);
        presentAmountRecord.setCecId(cecId);
        presentAmountRecord.setCcsdId(ccsdId);
        presentAmountRecordMapper.insert(presentAmountRecord);
        return presentAmountRecord;
    }

    @Override
    public PresentAmountRecord createRecord(BigDecimal presentAmt, BigDecimal returnCash, String bussinessName, String mobilePhone, String orderNo, String purpose, Long cecId, Long ccsdId) {
        PresentAmountRecord presentAmountRecord=new PresentAmountRecord();
        presentAmountRecord.setPresentAmount(presentAmt);
        presentAmountRecord.setBusinessName(bussinessName);
        presentAmountRecord.setMobilePhone(mobilePhone);
        presentAmountRecord.setOrderNo(orderNo);
        presentAmountRecord.setPurpose(purpose);
        presentAmountRecord.setCecId(cecId);
        presentAmountRecord.setCcsdId(ccsdId);
        presentAmountRecord.setReturnCashAmount(returnCash);
        presentAmountRecordMapper.insert(presentAmountRecord);
        return presentAmountRecord;
    }
}
